<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="edu.columbia.ubms.ejb.BlogBoxSessionBeanRemote" %>
<%@ page import="edu.columbia.ubms.ejb.Item" %>

<%@ include file="sessionCheck.jsp"%>

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Blog Box View</title>
<link rel="stylesheet" type="text/css" href="ubms.css" media="screen" />
<script language="javaScript">
function checkBox() {
	if (document.regform.sharecheck.checked) {
		document.regform.blogboxshare.value = "Y";
	} else {
		document.regform.blogboxshare.value = "N";
	}
}
</script>
</head>
<body>
<%
int userId = (Integer)session.getAttribute("userid");
int blogBoxId = Integer.parseInt((String)request.getParameter("blogboxid"));

try {   
    Context ctx = new InitialContext();		
    BlogBoxSessionBeanRemote beanRemote = (BlogBoxSessionBeanRemote)ctx.lookup("BlogBoxSessionBean/remote");
	Item item = beanRemote.blogBoxGet(userId, blogBoxId);
	
	String blogBoxShareCheck = "";
	if (item.getBlogboxShare() == 'Y') {
		blogBoxShareCheck = "checked";
	}
%>
<form name="regform" action="blogBoxUpdate.jsp" method="post">
	<table>
		<tr>
			<td>Name</td><td><input type="text" name="blogboxname" value="<%=item.getBlogboxName()%>"/></td>
		</tr>
		<tr>
			<td>Tag</td><td><input type="text" name="blogboxtag" value="<%=item.getBlogboxTag()%>"/></td>
		</tr>
		<tr>
			<td>Share</td><td><input type="checkbox" name="sharecheck" onClick="checkBox();" <%=blogBoxShareCheck%>/></td>
		</tr>
	</table>
	<input type="hidden" name="blogboxshare" value="<%=item.getBlogboxShare()%>"/>
	<input type="hidden" name="blogboxid" value="<%=blogBoxId%>"/>
	<input type="submit" value="Register">
</form>
<a href="blogBoxDelete.jsp?blogboxid=<%=blogBoxId%>">Delete</a>
<%
} catch(Exception e) {
    out.println("Error:" + e.getMessage());
}	
%>
</body>
</html>